import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores'
// import{ ref } from 'vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/login/LoginPage.vue')
    },
    {
      path: '/',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '',
          component: () => import('@/views/Home/index.vue')
        },
        {
          path: '/Company',
          component: () => import('@/views/Company/index.vue')
        },
        {
          path: '/Job',
          component: () => import('@/views/Job/index.vue')
        },
        {
          path: '/forum',
          component: () => import('@/views/Forum/index.vue')
        },
        {
          path: '/communication',
          component: () => import('@/views/Communication/index.vue')
        },
        {
          path: '/userInfo',
          component: () => import('@/views/userInfo/index.vue')
        },
        {
          path: '/JobInfo',
          component: () => import('@/views/JobInfo/index.vue')
        },
        {
          path: '/Resume',
          component: () => import('@/views/Resume/index.vue')
        },
        {
          path: '/CompanyInfo',
          component: () => import('@/views/CompanyInfo/index.vue'),
          children: [
            {
              path: '',
              component: () =>
                import('@/views/CompanyInfo/CompanyProfile/index.vue')
            },
            {
              path: '/CompanyJobInfo',
              component: () =>
                import('@/views/CompanyInfo/CompanyJob/index.vue')
            }
          ]
        }
      ]
    },
    {
      path: '/test',
      component: () => import('@/views/Home/test.vue')
    }
  ]
})

router.beforeEach((to) => {
  const userStore = useUserStore()
  if (!userStore.token && to.path != '/login') return '/login'
})
export default router
